// unique_ptr实现
// 拷贝和赋值都被禁用导致一个对象只管理一个资源

#include <iostream>

template<typename Type>
class unique_ptr
{
private:
    Type* _pointer;

public:
    unique_ptr(Type* pointer) : _pointer(pointer) {}

    unique_ptr(unique_ptr<Type>& uniquePtr) = delete;
    unique_ptr<Type>& operator=(unique_ptr<Type>& uniquePtr) = delete;

    ~unique_ptr()
    {
        if(_pointer != nullptr)
        {
            delete _pointer;
        }
    }

    Type& operator*()
    {
        return *_pointer;
    }

    Type* operator->()
    {
        return _pointer;
    }
};

int main()
{
    unique_ptr<int> u1(new int);
    *u1 = 100;
    std::cout << "*u1 : " << *u1 << std::endl;
    return 0;
}
